Add opt-in interactive-session idle auto-close (sessions.interactive_archive_after_hours)#182
Open
serxa wants to merge 2 commits into
Open
Add opt-in interactive-session idle auto-close (sessions.interactive_archive_after_hours)#182serxa wants to merge 2 commits into
serxa wants to merge 2 commits into
Conversation
…r_hours) Interactive chat sessions were only cleaned by the 30-day staleness backstop and the max_sessions cap. Leaving them open for days delays memory consolidation (a session is memorized on close), keeps stale context around to be reloaded/re-cached on resume, silently resumes day-old threads, and lets an unanswered ask_user question dangle. This adds an opt-in short idle cutoff to address that. sessions.archive_after_hours (default 0 = disabled) archives interactive sessions (web/telegram/discord/slack/whatsapp) idle beyond it, memorizing them and expiring any pending question; cron/persistent sessions are excluded. Default behavior is unchanged: the block is skipped when 0, and the cleanup cadence stays 6h unless the feature is enabled (then hourly). Adds additive SessionStore.get_stale_interactive_sessions + NotificationStore.expire_pending_questions_for_session, and tests incl. a default-unchanged case. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…rity The knob is scoped to interactive sources only (distinct from the global archive_after_days backstop that covers cron/persistent/external too), so the explicit name avoids it reading like a finer-grained archive_after_days. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation — why you'd enable this
Nerve only cleaned up interactive sessions via a 30-day staleness backstop and the
max_sessionsoverflow cap. Leaving idle chat sessions (web/telegram/…) open for days has real downsides that an opt-in short idle cutoff addresses:ask_userand the user never answered, that pending question lingers on the open session. Auto-closing the idle session expires it cleanly, so there's no phantom pending question (and nothing for the periodic expiry pass to try to inject into a session the user has clearly moved on from).It's opt-in precisely because the opposite preference is also valid — users who want long-lived, always-resumable sessions simply leave it off (the default).
Why a separate knob (not just a smaller
archive_after_days)archive_after_daysis global — it archives every session class (cron, persistent-cron which reuse a session across runs, and external/satellite sessions). Lowering it to close chats quickly would also prematurely archive those and break their continuity. Interactive and background sessions simply want different retention, so this is a distinct, interactive-scoped policy — hence the explicit nameinteractive_archive_after_hoursrather than a finer-grainedarchive_after_days.What it does
Adds
sessions.interactive_archive_after_hours(default0= disabled). When set > 0, the periodic cleanup also archives interactive sessions (web/telegram/discord/slack/whatsapp) idle longer than that many hours — memorizing them and expiring any pendingask_userquestion. Cron and persistent sessions are excluded (they keep their own long rotation / thearchive_after_daysbackstop).SessionsConfig.interactive_archive_after_hours(+from_dict).SessionManager.run_cleanup(..., interactive_archive_after_hours=0)— the short cutoff, skipped entirely when 0.SessionStore.get_stale_interactive_sessionsandNotificationStore.expire_pending_questions_for_session(both additive).Default behaviour is unchanged
interactive_archive_after_hoursdefaults to 0, and the new cutoff block is skipped entirely when 0.archived_interactivestat is0when disabled.Testing
Added
TestArchiveAndCleanupcases: disabled (default) leaves idle interactive sessions untouched, enabled archives them, and cron sessions are excluded even when enabled. Full suite:1550 passed, 2 skipped.